package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {
    /**
     * 根据分类id查询菜品数量
     *
     * @param categoryId
     * @return
     */
    @Select("select count(*) from dish where category_id = #{categoryId}")
    Integer countByCategore(Long categoryId);

    /**
     * 分页查询
     * @param categoryId
     * @param name
     * @param status
     * @return
     */
    Page<Dish> list(Integer categoryId, String name, Integer status);
    /**
     * 插入菜品数据
     * @param dish
     */

@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")//获取主键值，并且赋值给id属性
    @AutoFill(OperationType.INSERT)
    @Insert("insert into dish (name,category_id,price,status,create_time,update_time,create_user,update_user) values (#{name},#{categoryId},#{price},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Dish dish);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish selectById(Long id);

    void deleteBatch(List<Long> ids);
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> all(Long categoryId);
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);
   @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    List<Dish> listBy(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}






